package com.gigmissions.client.ui;

import com.gigmissions.client.config.GigMissionsMessages;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class MainTabPanel extends DecoratedTabPanel {
	
	private MapWidget map;
	private HomePanel homePanel;
	
	
	@Inject
	public MainTabPanel(HomePanel homePanel,AddGigPanel addGigPanel,final MapWidget map,GigMissionsMessages messages){
		
		this.homePanel = homePanel;
		this.map = map;
		setWidth("100%");
		setHeight("100%");
	    setAnimationEnabled(false);
	    add(homePanel,messages.homeTabTitle());
	    add(addGigPanel,messages.addGigLink());
	    add(map,messages.gigMapTabTitle());
	    this.getDeckPanel().setHeight("90%");
	    this.getDeckPanel().setWidth("97%");
	    	    	
	    this.addSelectionHandler(new SelectionHandler<Integer>(){

			@Override
			public void onSelection(SelectionEvent<Integer> event) {
				LatLng center = LatLng.newInstance(map.getCenter().getLatitude(), map.getCenter().getLongitude());
				map.checkResize();
				map.setCenter(center);
			}
	    	
	    });
	    
	    this.selectTab(0);

	}
	
	public MapWidget getMapWidget(){
		
		return this.map;
	}
	
	public HomePanel getHomePanel(){
		return this.homePanel;
		
	}
	


}
